/**
 * 
 * 找出一个数组中和为 n 的两个数  利用二分法  实现双指针 时间复杂度O(n)
 */

const PointerTofind = (array:number[],target:number)=>{
    let leftPoint = 0;
    let rightPoint = array.length - 1
    let res = []
    while(leftPoint < rightPoint){
        let sum = array[leftPoint] + array[rightPoint]
        if(sum < target){
            leftPoint++
        }else if(sum > target){
            rightPoint--
        }else{
            res.push(array[leftPoint],array[rightPoint])
            return res
        }
    }
}


const res = PointerTofind([1,2,3,6,9,],8)
console.log(res)

